var menu = document.getElementById("menu");
document.oncontextmenu = function (e) {
  // 鼠标点的坐标;
  var oX = e.clientX;
  var oY = e.clientY;
  // 不让它进墙里去
  var winWidth = window.innerWidth;
  var winHeight = window.innerHeight;
  var cmWidth = menu.offsetWidth;
  var cmHeight = menu.offsetHeight;
  oX = oX > winWidth - cmWidth ? winWidth - cmWidth : oX;
  oY = oY > winHeight - cmHeight ? winHeight - cmHeight : oY;
  //菜单出现后的位置
  menu.style.visibility = "visible";
  menu.style.left = oX + "px";
  menu.style.top = oY + "px";
  return false; //阻止右键弹窗
};
// 清除菜单
document.onclick = function (e) {
  menu.style.visibility = "hidden";
};
